﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace Furion.Core
{
    public class Permission: Entity, IEntitySeedData<Permission>
    {
        public Permission()
        {
            CreatedTime = DateTime.Now;
            Enabled = true;
            Ord = 0;
        }


        /// <summary>
        /// 权限名称
        /// </summary>
        [Required, MaxLength(50)]
        [Comment("权限名称")]
        public string PermissionName { get; set; }


        /// <summary>
        /// 权限代码（每一个接口）
        /// </summary>
        [Required, MaxLength(50)]
        [Comment("权限代码")]
        public string PermissionCode { get; set; }


        /// <summary>
        /// 排序
        /// </summary>
        [Required]
        [Comment("排序")]
        public int Ord { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        [Comment("是否启用")]
        public bool Enabled { get; set; }





        /// <summary>
        /// 分组
        /// </summary>
        [Comment("分组")]
        public int Sort { get; set; }





        /// <summary>
        /// 创建者Id
        /// </summary>
        [Comment("创建者Id")]
        public long? CreatedUserId { get; set; }

        /// <summary>
        /// 创建者名称
        /// </summary>
        [Comment("创建者名称")]
        [MaxLength(20)]
        public string CreatedUserName { get; set; }

        /// <summary>
        /// 修改者Id
        /// </summary>
        [Comment("修改者Id")]
        public long? UpdatedUserId { get; set; }

        /// <summary>
        /// 修改者名称
        /// </summary>
        [Comment("修改者名称")]
        [MaxLength(20)]
        public string UpdatedUserName { get; set; }

        /// <summary>
        /// 软删除
        /// </summary>
        [JsonIgnore]
        [Comment("软删除标记")]
        public bool IsDeleted { get; set; } = false;


        /// <summary>
        /// 多对多
        /// </summary>
        public ICollection<Role> Roles { get; set; }

        /// <summary>
        /// 多对多中间表
        /// </summary>
        public List<RolePermission> RolePermissions { get; set; }



        /// <summary>
        /// 种子数据
        /// </summary>
        /// <param name="dbContext"></param>
        /// <param name="dbContextLocator"></param>
        /// <returns></returns>
        public IEnumerable<Permission> HasData(DbContext dbContext, Type dbContextLocator)
        {
            List<Permission> list = new List<Permission>();

            list.Add(new Permission { Id = 1, PermissionName = "当前登录用户", PermissionCode = ConstPermission.USER_Profile, Sort=0, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 2, PermissionName = "用户列表", PermissionCode = ConstPermission.USER_List, Sort = 0, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 3, PermissionName = "用户信息编辑", PermissionCode = ConstPermission.USER_Edit, Sort = 0, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 4, PermissionName = "用户删除", PermissionCode = ConstPermission.USER_Delete, Sort = 0, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 5, PermissionName = "用户新增", PermissionCode = ConstPermission.USER_Add, Sort = 0, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 6, PermissionName = "用户密码修改", PermissionCode = ConstPermission.USER_ChangePassword, Sort = 0, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });

            list.Add(new Permission { Id = 7, PermissionName = "文件上传", PermissionCode = ConstPermission.File_Upload, Sort = 1, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 8, PermissionName = "文件下载", PermissionCode = ConstPermission.File_Download, Sort = 1, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });



            list.Add(new Permission { Id = 9, PermissionName = "部门新增", PermissionCode = ConstPermission.Org_Add, Sort = 2, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 10, PermissionName = "部门编辑", PermissionCode = ConstPermission.Org_Edit, Sort = 2, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 11, PermissionName = "部门删除", PermissionCode = ConstPermission.Org_Delete, Sort = 2, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 12, PermissionName = "部门列表", PermissionCode = ConstPermission.Org_List, Sort = 2, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });

            list.Add(new Permission { Id = 13, PermissionName = "权限新增", PermissionCode = ConstPermission.Permission_Add, Sort = 3, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 14, PermissionName = "权限编辑", PermissionCode = ConstPermission.Permission_Edit, Sort = 3, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 15, PermissionName = "权限删除", PermissionCode = ConstPermission.Permission_Delete, Sort = 3, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 16, PermissionName = "权限列表", PermissionCode = ConstPermission.Permission_List, Sort = 3, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });

            list.Add(new Permission { Id = 17, PermissionName = "角色新增", PermissionCode = ConstPermission.Role_Add, Sort = 4, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 18, PermissionName = "角色编辑", PermissionCode = ConstPermission.Role_Edit, Sort = 4, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 19, PermissionName = "角色删除", PermissionCode = ConstPermission.Role_Delete, Sort = 4, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 20, PermissionName = "角色列表", PermissionCode = ConstPermission.Role_List, Sort = 4, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 21, PermissionName = "角色权限设置", PermissionCode = ConstPermission.Role_Permission, Sort = 4, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });

            list.Add(new Permission { Id = 22, PermissionName = "政策新增", PermissionCode = ConstPermission.Policy_Add, Sort = 5, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 23, PermissionName = "政策编辑", PermissionCode = ConstPermission.Policy_Edit, Sort = 5, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 24, PermissionName = "政策删除", PermissionCode = ConstPermission.Policy_Delete, Sort = 5, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 25, PermissionName = "政策列表", PermissionCode = ConstPermission.Policy_List, Sort = 5, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 26, PermissionName = "政策恢复", PermissionCode = ConstPermission.Policy_Recovery, Sort = 5, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 27, PermissionName = "政策导出", PermissionCode = ConstPermission.Policy_ImportOut, Sort = 5, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });

 
            list.Add(new Permission { Id = 28, PermissionName = "字典新增", PermissionCode = ConstPermission.Dictionary_Add, Sort = 6, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 29, PermissionName = "字典编辑", PermissionCode = ConstPermission.Dictionary_Edit, Sort = 6, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 30, PermissionName = "字典删除", PermissionCode = ConstPermission.Dictionary_Delete, Sort = 6, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 31, PermissionName = "字典列表", PermissionCode = ConstPermission.Dictionary_List, Sort = 6, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });
            list.Add(new Permission { Id = 32, PermissionName = "字典恢复", PermissionCode = ConstPermission.Dictionary_Recovery, Sort = 6, Ord = 0, Enabled = true, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now });





            return list;
        }

    }
}
